﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200056D RID: 1389
	public class AnimeList : MonoBehaviour
	{
		// Token: 0x1700044A RID: 1098
		// (get) Token: 0x06002381 RID: 9089 RVA: 0x000D606C File Offset: 0x000D426C
		// (set) Token: 0x06002382 RID: 9090 RVA: 0x000D607C File Offset: 0x000D427C
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
				}
			}
		}

		// Token: 0x06002383 RID: 9091 RVA: 0x000D609C File Offset: 0x000D429C
		public void InitList(AnimeGroupList.SEX _sex, int _group, int _category)
		{
			int childCount = this.transformRoot.childCount;
			for (int i = 0; i < childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.scrollRect.verticalNormalizedPosition = 1f;
			this.dicNode = new Dictionary<int, Image>();
			foreach (KeyValuePair<int, Info.AnimeLoadInfo> keyValuePair in ((_sex != AnimeGroupList.SEX.Male) ? Singleton<Info>.Instance.dicFemaleAnimeLoadInfo[_group][_category] : Singleton<Info>.Instance.dicMaleAnimeLoadInfo[_group][_category]))
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectPrefab);
				if (!gameObject.activeSelf)
				{
					gameObject.SetActive(true);
				}
				gameObject.transform.SetParent(this.transformRoot, false);
				GameSceneNode component = gameObject.GetComponent<GameSceneNode>();
				int no = keyValuePair.Key;
				component.AddActionToButton(delegate
				{
					this.OnSelect(no);
				});
				component.text = keyValuePair.Value.name;
				this.dicNode.Add(keyValuePair.Key, gameObject.GetComponent<Image>());
			}
			this.sex = _sex;
			this.group = _group;
			this.category = _category;
			this.select = -1;
			this.active = true;
		}

		// Token: 0x06002384 RID: 9092 RVA: 0x000D623C File Offset: 0x000D443C
		private void OnSelect(int _no)
		{
			this.mpCharCtrl.LoadAnime(this.sex, this.group, this.category, _no);
			int key = this.select;
			if (Utility.SetStruct<int>(ref this.select, _no))
			{
				Image image = null;
				if (this.dicNode.TryGetValue(key, out image) && image != null)
				{
					image.color = Color.white;
				}
				image = null;
				if (this.dicNode.TryGetValue(this.select, out image) && image != null)
				{
					image.color = Color.green;
				}
			}
		}

		// Token: 0x0400246F RID: 9327
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x04002470 RID: 9328
		[SerializeField]
		private GameObject objectPrefab;

		// Token: 0x04002471 RID: 9329
		[SerializeField]
		private ScrollRect scrollRect;

		// Token: 0x04002472 RID: 9330
		[SerializeField]
		private MPCharCtrl mpCharCtrl;

		// Token: 0x04002473 RID: 9331
		private AnimeGroupList.SEX sex = AnimeGroupList.SEX.Unknown;

		// Token: 0x04002474 RID: 9332
		private int group = -1;

		// Token: 0x04002475 RID: 9333
		private int category = -1;

		// Token: 0x04002476 RID: 9334
		private int select = -1;

		// Token: 0x04002477 RID: 9335
		private Dictionary<int, Image> dicNode;
	}
}
